package com.fulin.date;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Description TODO
 * @Author fulin16
 * @Date 2020/12/11 10:54
 **/
public class TimeZoneTest {
    public final static String DEFAULT_PATTERN 	= "yyyy-MM-dd HH:mm:ss";
    private final static DateTimeFormatter DEFAULT_FORMAT = DateTimeFormatter.ofPattern(DEFAULT_PATTERN);//默认时间字符格式

    public static void main(String[] args) {
//        ZoneId zoneId = ZoneId.systemDefault();
        ZoneId zoneId = ZoneId.of("UTC+8");
        String id = zoneId.getId();
        System.out.println(id);
        Date date = new Date();
        String format = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), zoneId).format(DEFAULT_FORMAT);
        Date from = Date.from(date.toInstant().atZone(zoneId).toLocalDate().plusDays(0).atStartOfDay(zoneId).toInstant());

        System.out.println(format);
        System.out.println(from.getTime());//1607619600000 / 1607616000000
    }
}
